<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/***
	报价项目-销售模块：下委托、查看已委托项目、上传商务标书、查看已完成项目、查看已取消项目。
	
**/
class Bid_sales extends CI_Controller {
	
	public function __construct() {
		parent::__construct();
		$this->load->library('session');
		$this->load->model('bid_sales_model');
		$this->load->model('bid_project_code_model');
		$this->load->helper('url');
	}
	//默认查看已委托项目
	public function index() {
		isset($_SESSION['user_name']) OR exit('请先登录！');	
		$user_id = $_SESSION['user_id'];
		
		//传来下委托表单
		if (isset($_POST['form1'])) {
			$project_id = $_POST['project_id'];
			$this->bid_sales_model->entrust($project_id);
		}
		
		//传来修改委托表单
		if (isset($_POST['form2'])) {
			$project_id = $_POST['project_id'];
			$this->bid_sales_model->edit_entrust($project_id);
		}
		
		//搜出所有entrust_status = 1的项目
		$data['projects'] = $this->bid_sales_model->get_by_entrust(1, $user_id);
		$data['title'] = "已委托项目列表";
		$this->load->library('parser');
		
		$this->load->view('templates/head');
		$this->load->view('templates/menu');
		$this->parser->parse('bid_sales/list_entrusted', $data);
		
		$this->load->view('templates/foot');
	}
	
	
	//下委托
	public function entrust($id = 0) {
		isset($_SESSION['user_name']) OR exit('请先登录！');
		$user_id = $_SESSION['user_id'];
		//先列未委托表
		//下委托由链接发过来$id，给出委托表单
		//由index接受委托表单，并显示已委托项目表
		
		$this->load->library('parser');
		$this->load->view('templates/head');
		$this->load->view('templates/menu');
		
		if ($id <> 0) {
			//由id获取项目信息
			$project = $this->bid_project_code_model->get_by_id ($id);
			$data['project_id'] = $id;
			$data['project_code'] = $project['code'];
			$data['project_name'] = $project['name'];
			$data['sale_name'] = $project['sale_name'];
			
			$this->parser->parse('bid_sales/form_entrust', $data);
		} else {
		
			//搜出所有entrust_status = 0的项目
			$data['projects'] = $this->bid_sales_model->get_by_entrust(0, $user_id);
			$data['title'] = "未委托项目列表";
		
			$this->parser->parse('bid_sales/list_entrust', $data);
		}
		$this->load->view('templates/foot');
	}
	
	public function edit_entrust ($id = 0) {
		isset($_SESSION['user_name']) OR exit('请先登录！');
		
		$this->load->library('parser');
		$this->load->view('templates/head');
		$this->load->view('templates/menu');
		//由id获取项目信息
		$project = $this->bid_sales_model->get_by_id ($id);
		$data['project_id'] = $id;
		$data['project_code'] = $project['code'];
		$data['project_name'] = $project['name'];
		$data['sale_name'] = $project['sale_name'];
		$data['client'] = $project['client'];
		$data['rfq_no'] = $project['rfq_no'];
		$data['end_user'] = $project['end_user'];
		$data['place'] = $project['place'];
		$data['bid_type'] = $project['bid_type'];
		$data['deadline'] = $project['deadline'];
		$data['classification'] = $project['classification'];
		$data['currency'] = $project['currency'];
		$data['delivery_term'] = $project['delivery_term'];
			
		$this->parser->parse('bid_sales/form_entrusted', $data);
		$this->load->view('templates/foot');
	}
}
